#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int t,a[N],c[N];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&t);
    while(t--){
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            c[i]=0;
        }
        for(int i=1;i<=n;i++){
            for(int j=i-1;j>=1;j--){
                if(a[j]==a[i]) c[i]=a[i];
            }
        }
        int ans=0;
        for(int i=1;i<=n;i++){
            ans+=c[i];
        }
        printf("%d\n",ans);
    }
    return 0;
}
